﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paringlihtv2_ettevote", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(Paringlihtv2Ettevote))]
    public class Paringlihtv2EttevoteSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParinglihtv2Ettevote clazz;
        
        public Paringlihtv2EttevoteSerializer(IParinglihtv2Ettevote clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("evnimi");
            if (clazz.Evnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Evnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Evnimi");
            }
            Writer.WriteEndElement();
            if (clazz.KehtetudNimed!=null) {
                Writer.WriteStartElement("kehtetud_nimed");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("paringliht_kehtetunimi", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.KehtetudNimed.Count);
                for (int x = 0; ((clazz.KehtetudNimed != null) 
                            && (x < clazz.KehtetudNimed.Count)); x = (x + 1)) {
                    if (clazz.KehtetudNimed[x]!=null) {
                        Writer.WriteStartElement("evnimi");
                        global::Xtee.Core.SerializationMetadata metaKehtetudNimed = this.GetMetaData(clazz.KehtetudNimed[x]);
                        Writer.WriteTypeAttribute(metaKehtetudNimed.TypeQualifiedName.Namespace, metaKehtetudNimed.TypeQualifiedName.Name);
                        metaKehtetudNimed.NewSerializer(clazz.KehtetudNimed[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("ariregistri_kood");
            if (clazz.AriregistriKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AriregistriKood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AriregistriKood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("staatus");
            if (clazz.Staatus!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_evstaatus");
                Writer.WriteString(clazz.Staatus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Staatus");
            }
            Writer.WriteEndElement();
            if (clazz.Tegutseb!=null) {
                Writer.WriteStartElement("tegutseb");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tegutseb))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TegutsebTekstina!=null) {
                Writer.WriteStartElement("tegutseb_tekstina");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TegutsebTekstina))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("registrist_kustutamise_aeg");
            if (clazz.RegistristKustutamiseAeg!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RegistristKustutamiseAeg))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("piirkond");
            if (clazz.Piirkond!=null) {
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_piirkond");
                Writer.WriteString(clazz.Piirkond.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Piirkond");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("evkapitalid");
            if (clazz.Evkapitalid!=null) {
                global::Xtee.Core.SerializationMetadata metaEvkapitalid = this.GetMetaData(clazz.Evkapitalid);
                Writer.WriteTypeAttribute(metaEvkapitalid.TypeQualifiedName.Namespace, metaEvkapitalid.TypeQualifiedName.Name);
                metaEvkapitalid.NewSerializer(clazz.Evkapitalid).WriteXml(Writer);
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("evaadressid");
            if (clazz.Evaadressid!=null) {
                global::Xtee.Core.SerializationMetadata metaEvaadressid = this.GetMetaData(clazz.Evaadressid);
                Writer.WriteTypeAttribute(metaEvaadressid.TypeQualifiedName.Namespace, metaEvaadressid.TypeQualifiedName.Name);
                metaEvaadressid.NewSerializer(clazz.Evaadressid).WriteXml(Writer);
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("esmakande_aeg");
            if (clazz.EsmakandeAeg!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EsmakandeAeg))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="evnimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringlihtv2_ettevote>evnimi");
                }
                clazz.Evnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("evnimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>evnimi", Reader.LocalName);
            }
            if (Reader.LocalName=="kehtetud_nimed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringlihtv2_ettevote>kehtetud_nimed");
                }
                clazz.KehtetudNimed = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtKehtetunimi>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kehtetud_nimed");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "evnimi")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringliht_kehtetudnimed>evnimi");
                        }
                        global::Xtee.Core.SerializationMetadata metaKehtetudNimed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtKehtetunimi>(Reader, "paringliht_kehtetunimi", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtKehtetunimi item = metaKehtetudNimed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtKehtetunimi>();
                        clazz.KehtetudNimed.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("evnimi");
                            metaKehtetudNimed.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringlihtv2_ettevote>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="staatus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringlihtv2_ettevote>staatus");
                }
                clazz.Staatus = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XEvstaatus(Reader.ReadElementString("staatus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>staatus", Reader.LocalName);
            }
            if (Reader.LocalName=="tegutseb") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringlihtv2_ettevote>tegutseb");
                }
                clazz.Tegutseb = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tegutseb")).Value;
            }
            if (Reader.LocalName=="tegutseb_tekstina") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringlihtv2_ettevote>tegutseb_tekstina");
                }
                clazz.TegutsebTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tegutseb_tekstina")).Value;
            }
            if (Reader.LocalName=="registrist_kustutamise_aeg") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.RegistristKustutamiseAeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("registrist_kustutamise_aeg")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>registrist_kustutamise_aeg", Reader.LocalName);
            }
            if (Reader.LocalName=="piirkond") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringlihtv2_ettevote>piirkond");
                }
                clazz.Piirkond = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XPiirkond(Reader.ReadElementString("piirkond"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>piirkond", Reader.LocalName);
            }
            if (Reader.LocalName=="evkapitalid") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaEvkapitalid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtEvkapital>(Reader, "paringliht_evkapital", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    clazz.Evkapitalid = metaEvkapitalid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtEvkapital>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("evkapitalid");
                        metaEvkapitalid.NewSerializer(clazz.Evkapitalid).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>evkapitalid", Reader.LocalName);
            }
            if (Reader.LocalName=="evaadressid") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaEvaadressid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtEvaadress>(Reader, "paringliht_evaadress", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    clazz.Evaadressid = metaEvaadressid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtEvaadress>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("evaadressid");
                        metaEvaadressid.NewSerializer(clazz.Evaadressid).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>evaadressid", Reader.LocalName);
            }
            if (Reader.LocalName=="esmakande_aeg") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.EsmakandeAeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("esmakande_aeg")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringlihtv2_ettevote>esmakande_aeg", Reader.LocalName);
            }
        }
    }
}
